import openpyxl
import datetime
import threading

"""
2023-10-04 11:23:23.533482
2023-10-04 11:38:23.671265
3600条信息 查找输入 花费15分钟  效率很低

修改以后采用函数字典传值 3600条数据 大概4分钟查找 有进展 优点 逐行读取 字典传值
2023-10-04 20:04:36.674405
2023-10-04 20:07:18.889834
可能跟计算机性能有关

思考有没有更便捷的方法呢？
"""
# 读取一张表 将数值写进另一张表
# 读取两张表
workbook = openpyxl.load_workbook(filename='结果表1.xlsx')
workbook1 = openpyxl.load_workbook(filename='名单表二.xlsx')
# 实例化 两张表
jg = workbook['Sheet1']
md = workbook1['Sheet1']

row = jg.max_row
row1 = md.max_row
a = datetime.datetime.now()


def search(data):
    for y in jg.iter_rows(min_row=5, max_row=jg.max_row, values_only=True):
        if data['姓名'] == y[3]:
            if data['项目名称'] == y[4]:
                data1 = {
                    '检验结果': y[5],
                    '结果标志': y[6],
                }
                print(f"{y[3]}{y[4]}已找到")
                return data1


for i in range(5, row1 + 1):
    data = {
        '姓名': md[f'D{i}'].value,
        '项目名称': md[f'E{i}'].value,
    }
    md[f'F{i}'].value = search(data)['检验结果']
    md[f'G{i}'].value = search(data)['结果标志']

# for i in range(5, row1 + 1):
#     for y in range(5, row + 1):
#         if md[f'D{i}'].value == jg[f'D{i}'].value:
#             if jg[f'E{i}'].value == 'WBC':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'RBC':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'HGB':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'HCT':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'MCV':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'MCH':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'MCHC':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'PLT':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'NEUT%':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'NEUT#':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'LYM%':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'LYM#':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'MONO%':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'MONO#':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'Eos%':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'Eos#':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'BASO%':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'BASO#':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'RDW-CV':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'MPV':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'PCT':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'RDW-SD':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'
#
#             if jg[f'E{i}'].value == 'PDW':
#                 md[f'F{i}'].value = jg[f'F{i}'].value
#                 if jg[f'G{i}'].value == "H":
#                     md[f'G{i}'].value = '偏高'
#                 elif jg[f'G{i}'].value == "L":
#                     md[f'G{i}'].value = '偏低'
#                 else:
#                     md[f'G{i}'].value = '正常'


workbook1.save('名单表二.xlsx')
print(a)
print(datetime.datetime.now())
